<!-- START OF FUNCTIONS -->
<script type="text/javascript">
	<?php
	// Copy a php array into a javascript array.
	$array_JS="usrList";

	printf("%s = new Array();\n",$array_JS);

	for($i=0; $i < sizeof($clientUsr); $i++)
	{
		printf("%s[%s]= new Array();\n",$array_JS, $i);

				foreach($clientUsr[$i]['User'] as $key => $value)
				{
					if ($key == 'id' || $key == 'firstname' || $key == 'lastname' || $key == 'company_id'){
						printf("%s[%s].%s =%s;\n",$array_JS, $i, $key,
							is_string($value) ?  "\"".addslashes($value)."\"" : $value);
					}
				}
	}
	
	// Copy a php array into a javascript array.
	$array_JS="contractList";

	printf("%s = new Array();\n",$array_JS);

	for($i=0; $i < sizeof($contracts); $i++)
	{
		printf("%s[%s]= new Array();\n",$array_JS, $i);

				foreach($contracts[$i]['Contract'] as $key => $value)
				{
					printf("%s[%s].%s =%s;\n",$array_JS, $i, $key,
						is_string($value) ?  "\"".addslashes($value)."\"" : $value);
				}
	}
	?>
</script>

<?php echo $javascript->link('project_scripts.js');?>

<!-- END OF FUNCTIONS -->

<?php //pr($smileUsr); ?>

<div class="layoutProject">
	<div class="addProject">
		<?php echo $form->create('Project', array('action' => 'edit/'.$project['id'])); ?>
			<h2><?php echo __('project'); ?></h2>
			<?php echo __('project').$form->input('name', array('label' => false, 'value'=>$project['name'])); ?>
            
			<?php echo __('contract_choice').$form->select('contract_id', $format->buildContractArr($contracts), array($contract['Contract']['id'],$contract['Contract']['ref']), array('onChange'=>'javascript:update_client_list(this.options[this.options.selectedIndex].value)', 'error'=>'Please select a Contract.')); echo $html->link(__('create_contract', true), "/contracts/add/");
			echo $form->error('contract_id', 'Please select a Contract.'); ?>
            
            <?php echo "<br />Description<br />".$form->textarea('description', array('value'=>$project['description'])); ?>

			<div id="gescom">			
			<?php if (!isset($gescom)) { ?>

			<?php echo $ajax->link(__('link_to_gescom', true), '/gescom/add', array('update'=>'gescom')); ?>
			<?php } else {
				?>
				<h3>Gescom</h3>
				<?php
					echo $form->hidden('Gescom.id', array('value' => $gescom['id']));
					echo $form->input('Gescom.code_affaire', array('value' => $gescom['code_affaire']));
					echo $form->input('Gescom.code_client', array('value' => $gescom['code_client']));
			}?>
			</div>
			<h2>Smile</h2>
			<?php echo __('project_director').$form->select('smileDP.id', $format->buildUsrArr($smileUsr), $selectedPD, array('id'=>'smileDP'), false);?>
			<br />
			<?php echo __('team_leader').$form->select('smileCP.id', $format->buildUsrArr($smileUsr), $selectedTL, array('id'=>'smileCP'), false);?>
			
			<div class="users_selection_layout">
				<table border=0>
					<tr>
						<td>
							<?php echo $form->select('Smile_Left_List', $format->buildUsrArr($smileUsr)/*$smiles_dev*/, null, array('id' => 'SmileLeft', 'multiple' => 'multiple', 'size' => '10', 'style'=>'width:150px;'), False); ?>
						</td>
						<td>
							<input id="l2r_smile" name="left2right" type="button" value=">" onClick="javascript:switch_list('SmileLeft', 'SmileRight')">
							<br />
							<input id="r2l_smile" name="left2right" type="button" value="<" onClick="javascript:switch_list('SmileRight', 'SmileLeft')">
						</td>
						<td>
							<?php echo $form->select('smileDev.id', $selectedSmileDev, null, array('id' => 'SmileRight', 'multiple' => 'multiple', 'size' => '10', 'style'=>'width:150px;'), False); ?>
                            
						</td>
					</tr>
				</table>	
			</div>
			
			<h2>Client</h2>
			<?php echo __('team_leader').$form->select('clientCP.id', $format->buildUsrArr($clients), $selectedClientTL, array('id' => 'ClientCP')); ?>
			
			<div class="users_selection_layout">
				<table border=0>
					<tr>
						<td>
							<?php echo $form->select('Client_Left_List', $format->buildUsrArr($clients)/*$clients_dev*/, null, array('id' => 'ClientLeft', 'multiple' => 'multiple', 'size' => '10', 'style'=>'width:150px;'), False); ?>
						</td>
						<td>
							<input id="l2r_smile" name="left2right" type="button" value=">" onClick="javascript:switch_list('ClientLeft', 'ClientRight')">
							<br />
							<input id="r2l_smile" name="left2right" type="button" value="<" onClick="javascript:switch_list('ClientRight', 'ClientLeft')">
						</td>
						<td>
							<?php echo $form->select('clientDev.id', $selectedClientDev, null, array('id' => 'ClientRight', 'multiple' => 'multiple', 'size' => '10', 'style'=>'width:150px;'), False); ?>
						</td>
					</tr>
				</table>
			</div>
			
			<?php echo $form->submit(__('edit', true)); ?>
		<?php echo $form->end(); ?>
	</div>
</div>